<html> 
<head>
	<title> Success - Manage Template </title>
	<script>
	   function changeScreenSize(w,h)
		 {
		   window.resizeTo( w,h )
		 }
	</script>
</head>
<body onload="changeScreenSize(300,125)">
	<?php include ("write_functions.php");
	connect('localhost','root','','gradegrid');
	$selected_template = $_POST['template'];
	$template_id=$_POST['templateID'];
	$major_id=$_POST['majorID'];
	$class_id=$_POST['classid'];
	//modifytemplate($template_id,$selected_template);
	$modifytemplateofclass_query = "UPDATE class SET template_id = '".$template_id."' WHERE class_id =".$class_id;
	$update = mysql_query($modifytemplateofclass_query) or die(mysql_error());
	$counter=0;
	$id=100;
	$percentage=200;
	$query_major="SELECT * FROM major WHERE major.template_id='$template_id'";
	$result_major=mysql_query($query_major);
	$numMajor=mysql_numrows($result_major);
	//$numMajor=2;
	while($counter<$numMajor) {
		$new_majorid = $_POST["$id"];
		$new_majorname = $_POST["$counter"];
		$new_majorpercent = $_POST["$percentage"];
		//echo $new_majorpercent;
		//modifymajor($new_majorid,$new_majorname,$new_majorpercent);
		$counter++;
		$id++;
		$percentage++;
		
		$query_minor="SELECT minor.name, minor.maxrawscore, minor.name FROM major,minor WHERE major.major_id='$new_majorid' AND major.major_id=minor.major_id ORDER BY minor.name";
		$result_minor=mysql_query($query_minor);
		$numMinor=mysql_numrows($result_minor);
		$counter=0;
		$incrementMinorId=300;
		$incrementMinorName=400;
		$incrementMaxRaw=500;
		while($counter<$numMinor) {
			$new_minorid = $_POST["$incrementMinorId"];
			$new_minorname = $_POST["$incrementMinorName"];
			$new_maxraw= $_POST["$incrementMaxRaw"];
			//echo $new_minorname;
			//modifyminor($new_minorid,$new_minorname,$new_maxraw);
			$counter++;
			$incrementMinorId++;
			$incrementMinorName++;
			$incrementMaxRaw++;
		}
	}
	?>
	<h5>You have successfully modified your template.</h5>
</body>
</html>